#! python
# -*- coding: utf-8 -*-
from noise_generator import MATRIX
DEBUG = False


class Pixel():
    def __init__(self):
        self.x = 0
        self.y = 0

    def __repr__(self):
        return "x=%s, y=%s" % (self.x, self.y)


def get_items_on_map():
    pixels = [None for _ in xrange(45)]
    pixels[0] = '#59410e'
    pixels[1] = '#44371c'
    pixels[2] = '#393428'
    pixels[3] = '#3c3b3a'
    pixels[4] = '#3c3b3a'
    pixels[5] = '#2c2b2a'
    pixels[6] = '#202022'
    pixels[7] = '#1D1D1F'
    pixels[8] = '#14141a'

    # gold
    pixels[10] = '#AA7700'  # Simple
    pixels[11] = '#FFFF00'  # Cool

    # gemstones
    pixels[20] = '#8fddfa'  # Diamond
    pixels[21] = '#22AA33'  # Emerald
    pixels[22] = '#222299'  # Saphire
    pixels[23] = '#ae1a32'  # Ruby
    pixels[24] = '#3f6167'  # Aquamarine

    # pickaxes
    pixels[30] = '#888888'  # Pick
    pixels[31] = '#b96592'  # Health

    #portal
    pixels[40] = '#380236'  # Portal

    return pixels


def get_around_pixels(main_pixel_on_map, offset):
    """Returned List: [pixel, pixel...]"""
    result_pixels_list = list()

    area_width = MATRIX[0]
    area_height = MATRIX[1]

    w_square = (offset * 2) + 1
    s_pixels = w_square ** 2

    center_pixel_number = (s_pixels - 1) / 2

    for pixel_id_in_square in xrange(s_pixels):

        x = (pixel_id_in_square % w_square) - (offset - main_pixel_on_map.x)
        y = (pixel_id_in_square // w_square) - (offset - main_pixel_on_map.y)

        if DEBUG:
            print "x = %d" % x
            print "y = %d" % y

        # Pixel in area?
        if (area_width > x > -1) and (area_height > y > -1):
            if pixel_id_in_square != center_pixel_number:
                if DEBUG:
                    print "Add square id: %d" % pixel_id_in_square
                result_pixels_list.append([x, y])

    if DEBUG:
        print "w_square: [%d], s_pixels: [%d], center_pixel_number: [%d]" % (w_square, s_pixels, center_pixel_number)
    return result_pixels_list


def get_cross_pixels(central_pixel, offset, noise_map):
    """Returned Dict: {"up": [pixel, pixel...], "down": [pixel, pixel...], "left": [pixel...], "right": [pixel...]}"""

    result_pixels_dict = {"up": [], "down": [], "left": [], "right": []}

    area_width = len(noise_map[0])
    area_height = len(noise_map)

    for offset_counter in xrange(offset):
        current_offset = offset_counter + 1

        for side in xrange(4):

            x = central_pixel.x
            y = central_pixel.y

            if side == 0:
                y = central_pixel.y - current_offset
                if area_height > y > -1:
                    result_pixels_dict["up"].append((x, y))

            if side == 2:
                y = central_pixel.y + current_offset
                if area_height > y > -1:
                    result_pixels_dict["down"].append((x, y))

            if side == 1:
                x = central_pixel.x - current_offset
                if area_width > x > -1:
                    result_pixels_dict["left"].append((x, y))

            if side == 3:
                x = central_pixel.x + current_offset
                if area_width > x > -1:
                    result_pixels_dict["right"].append((x, y))

            if DEBUG:
                print("side ", side)
                print("current_offset, ", current_offset)
                print("x=", x)
                print("y=", y)
                print

    if DEBUG: print result_pixels_dict
    return result_pixels_dict